package gqz.mvvm.view;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;

import gqz.mvvm.R;
import gqz.mvvm.view.custom.FadeOutTextView;
import me.everything.android.ui.overscroll.HorizontalOverScrollBounceEffectDecorator;
import me.everything.android.ui.overscroll.IOverScrollDecor;
import me.everything.android.ui.overscroll.IOverScrollUpdateListener;
import me.everything.android.ui.overscroll.adapters.StaticOverScrollDecorAdapter;

/**
 * Created by Administrator on 2018/1/29.
 */

public class FadeOutTextActivity extends BaseActivity {

    Button btn_add;
    FadeOutTextView fadeOutTv;

    boolean addEnable = true, clearEnable = true;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fadeout_text);
        initView();
    }

    private void initView() {
        btn_add = (Button) findViewById(R.id.fadeOutText_btn_add);
//        btn_add.setOnClickListener(onclick);
        HorizontalOverScrollBounceEffectDecorator decorator = new HorizontalOverScrollBounceEffectDecorator(new StaticOverScrollDecorAdapter(btn_add));
        decorator.setOverScrollUpdateListener(new IOverScrollUpdateListener() {
            @Override
            public void onOverScrollUpdate(IOverScrollDecor decor, int state, float offset) {
                final View view = decor.getView();
                if (offset > 50 && addEnable) {
                    // '视图'目前正在从顶部过度滚动。
                    fadeOutTv.addText("addText");
                    addEnable = false;
                    clearEnable = false;
                } else if (offset < -50 && clearEnable) {
                    // '视图'目前正在从底部过度滚动。
                    fadeOutTv.clearText();
                } else if (offset == 0) {
                    addEnable = true;
                    clearEnable = true;
                } else {
                    // 没有过度滚动效果。
                    // 和(state == STATE_IDLE)相同.
                }
            }
        });
        fadeOutTv = (FadeOutTextView) findViewById(R.id.fadeOutText_fadeOutTv);
        fadeOutTv.setDisplayLineNum(9);
    }

    View.OnClickListener onclick = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.fadeOutText_btn_add:
                    fadeOutTv.addText("addText");
                    break;
            }
        }
    };
}
